package com.handu.luna.core.domain.goods.goodsMatch;

import com.handu.luna.core.domain.BaseRepository;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Set;

/**
 * Created by 123 on 2014/7/22.
 */
public interface GoodsMatchRepository extends JpaRepository<GoodsMatch,Long>,BaseRepository<GoodsMatch>,JpaSpecificationExecutor<GoodsMatch> {

    @Query("select cascadGoodsId from GoodsMatch where primaryGoodsId = :id")
    public Set<Long> findMatchedGoodsIdByPrimaryGoodsId(@Param("id")long id);

    @Query("select g from GoodsMatch g where g.primaryGoodsId = :id")
    public List<GoodsMatch> findByPrimaryGoodsId(@Param("id")long id);

    public List<GoodsMatch> findAll(Specification<GoodsMatch> specification);

    @Query("select g from GoodsMatch g where g.primaryGoodsId =:pid and g.cascadGoodsId = :mid")
    public List<GoodsMatch> checkByPidAndMid(@Param("pid")long pid,@Param("mid")long mid);

}
